load('lib/api_gpio.js');
load('lib/api_timer.js');
load('lib/api_uart.js');

let pin = 2;    // gpio 5
let s = ' ';

GPIO.set_mode(pin,GPIO.MODE_OUTPUT);
GPIO.set_pull(pin,GPIO.PULL_UP);

let pin2 = function(pin,data) {
    print("Pin",pin+1);
    GPIO.disable_int(pin);
};

GPIO.set_int_handler(pin, GPIO.INT_EDGE_NEG, pin2, null);

GPIO.set_int_handler(0,GPIO.INT_EDGE_ANY,function(pin){
    print("enable pin",2);
    GPIO.enable_int(2);
},null)

GPIO.enable_int(pin);
GPIO.enable_int(0);

UART.setConfig(0,{
        baudRate:9600,
        tx_buf_size:256
    });

UART.setDispatcher(0,function(uartNo,data){
        print(Timer.fmt('%Y-%m-%d %H:%M:%S :',Timer.now()),'recv data from serial ',UART.readAvail(0));
    },null);

UART.setRxEnabled(0,true);

print(Timer.fmt('%Y-%m-%d %H:%M:%S',Timer.now()));